#define  _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include <Windows.h>
#include <conio.h>
#include<locale.h>
#include <stdlib.h>

typedef struct item
{
    int ID;
    char name[100];
    int num;
    char unit[100];
}it;

it arr[100];

#define HIGH 3
#define LONG 10


int i = 0;
int k = 0;

void gotoxy(int x, int y)//形参
{
    HANDLE hOut;
    COORD pos = { x,y };
    // 光标的起始位（第1列，第3行） 0是第1列 2是第3行
    hOut = GetStdHandle(STD_OUTPUT_HANDLE);
    SetConsoleCursorPosition(hOut, pos);
    //printf("定位光标位置搜索(%d,%d)\n",pos.X,pos.Y);
}


void paintWin1(int Lon, int Hig, int x, int y, int i, int j)//15 3 0 0 3 4//15 3 15 0 3 4//15 3 60 0 3 4// 几行 几列
{
    gotoxy(x, y);
    if (x == 0 && y == 0)
    {
        printf("┏");
        for (int j = 1; j < Hig; j++)
        {
            gotoxy(x, j + y);
            printf("┃");
        }
    }

    else if (x != Lon * j  && y == 0)
    {
        printf("┬\n");
        for (int m = 1; m < Hig; m++)
        {
            gotoxy(x, m + y);
            printf("┃");
        }

        for (int m = 1; m < Hig; m++)
        {
            gotoxy(x + Lon, m +y);
            printf("┃\n");
        }
    }
    else if(x == Lon * j && y == 0)
    {
        gotoxy( Lon*j, y);
        printf("┓\n");
        return;
    }
    gotoxy(x + 1, y);
    for (int b = 1; b < Lon; b++) //添加横的线
    {
        printf("━");
    }
    
}
void paintWin2(int Lon, int Hig, int x, int y, int i, int j)//i,j 几行，几列  //15 2 0 2 3 4
{
        gotoxy(x, y + Lon);
        for (int m = 1; m < Hig; m++)
        {
            gotoxy(x, m + y);
            printf("┃\n");
        }
        gotoxy(x, y);      
        if (x == 0 )
        {
            printf("├");
        }
        else if (x != Lon * j )
        {
            printf("┼\n");
        }
        else if(x==Lon*j)
        {
            gotoxy(Lon*j, y);
            printf("┤\n");
            return;
        }
    gotoxy(x + 1, y);
    for (int b = 1; b < Lon; b++)
    {
        printf("━");
    }
}

void paintWin3(int Lon, int Hig, int x, int y, int i, int j)
{
    gotoxy(x, y);
    if (x == 0 && y == i * Hig)
    {
        printf("└");
    }
    else if (x !=j*Lon &&y==i*Hig)
    {
        printf("┴\n");
    }
    else if(x == Lon * j && y == Hig*i)
    {
        gotoxy(j* Lon, Hig*i);
        printf("┘\n");
        return;
    }
    gotoxy(x + 1, y);
    for (int b = 1; b < Lon; b++)
    {
        printf("━");
    }
}

void win1(int n, int m)//几行 列
{
    system("cls");
    for (int k = 0; k <= m; k++)
    {
        paintWin1(LONG, HIGH, LONG * k, 0, n, m);//x位置不断变化
    }
}
void win2(int n, int m)
{
    for (int z = 1; z < n; z++)
    {
        for (int k = 0; k <= m; k++)
        {
            paintWin2(LONG, HIGH, LONG * k, HIGH*z, n, m);
        }
    }
}
void win3(int n, int m)
{
    for (int k = 0; k <= m; k++)
    {
        paintWin3(LONG, HIGH, LONG * k, n*HIGH, n, m);//x位置不断变化
    }
}



int main()
{
    int n = 5, m = 4;
    printf("请输入n*m的方格数(注意 n<10 && m<8)");
    scanf("%d %d", &n, &m);

    win1(n, m);//可以使用函数封装
    win2(n, m);
    win3(n, m);

    gotoxy(4, 20);
    return 0;
}


